class Solution
{
public:
    static constexpr bool Left = false;
    static constexpr bool Right = true;
    static constexpr bool Down = false;
    static constexpr bool Up = true;
    int mirrorReflection(int p, int q)
    {
        if (q == 0)
        {
            return 0;
        }
        bool side = Right;
        bool direction = Up;
        int position = 0;
        while (true)
        {
            position += q;
            if (position == p)
            {
                if (side == Right)
                {
                    if (direction == Up)
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                }
                else
                {
                    // 不会回到原点
                    return 2;
                }
            }
            if (position > p)
            {
                direction = !direction;
                position -= p;
            }
            side = !side;
        }
        return -1;
    }
};